<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    //计算两个数的和
    // function getSum() {
    //   let num1 = +prompt('请输入第一个数字：')
    //   let num2 = +prompt('请输入第二个数字：')
    //   let sum = 0
    //   sum = num1 + num2
    //   console.log(sum);
    // }
    // getSum()
    // 计算1-100之间的和
    function addSum(x = 0, y = 0) {
      let sum = 0
      for (let i = x; i <= y; i++) {
        sum = sum + i
      }
      console.log(sum);
    }
    let num1 = +prompt('请输入第一个数：')
    let num2 = +prompt('请输入第二个数：')
    addSum(num1, num2)
    // 函数封装求和
    // function addSum(num1, num2) {
    //   let sum = 0
    //   for (let i = num1; i <= num2; i++) {
    //     sum = sum + i
    //   }
    //   console.log(sum);
    // }
    // addSum(2, 100)
  </script>
</body>

</html>